package com.aifast.gen.business.dao;

import com.aifast.gen.business.entity.GenTableColumn;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 代码生成业务表字段 Mapper 接口
 * </p>
 *
 * @author fujian
 * @since 2022-05-23
 */
@Mapper
public interface GenTableColumnDao extends BaseMapper<GenTableColumn> {

    @InterceptorIgnore(tenantLine = "true")
    @Select("select column_name, (case when (is_nullable = 'no' && column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type from information_schema.columns where table_schema = (select database()) and table_name = (#{table}) order by ordinal_position")
    List<GenTableColumn> getTableColumns(String table);



}
